﻿//+:cnd:noEmit

namespace Boilerplate.Shared.Dtos.Identity;

[DtoResourceType(typeof(AppStrings))]
public partial class SignInRequestDto : IdentityRequestDto
{
    /// <example>"123456"</example>
    [Display(Name = nameof(AppStrings.Password))]
    public string? Password { get; set; }

    /// <summary>
    /// Read SignInManagerExtensions.OtpSignInAsync comments.
    /// </summary>
    /// <example>null</example>
    [StringLength(6)]
    [Display(Name = nameof(AppStrings.Otp))]
    public string? Otp { get; set; }

    [JsonIgnore]
    [Display(Name = nameof(AppStrings.RememberMe))]
    public bool RememberMe { get; set; } = true;  // If false, it would store refreshToken temporarily. The accessToken itself is always short-lived.

    /// <summary>
    /// Two factor code generated by authenticator app
    /// </summary>
    /// <example>null</example>
    [Display(Name = nameof(AppStrings.TwoFactorCode))]
    public string? TwoFactorCode { get; set; }

    public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
    {
        var result = base.Validate(validationContext).ToList();

        if (string.IsNullOrEmpty(Password) && string.IsNullOrEmpty(Otp))
        {
            result.Add(new ValidationResult(
                errorMessage: nameof(AppStrings.EitherProvidePasswordOrOtp),
                memberNames: [nameof(Password), nameof(Otp)]
            ));
        }

        return result;
    }
}
